﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo13._1
{
    class Program
    {
        static void Main(string[] args)
        {
            float sum = 0;
            try
            {
                while (true)
                {
                    Console.WriteLine("请选择:1、存款，2、取款");
                    int key = int.Parse(Console.ReadLine());
                    switch (key)
                    {
                        case 1:
                            Console.WriteLine("请输入你想存的金额：");
                            float money = float.Parse(Console.ReadLine());
                            sum = sum + money;
                            break;

                        case 2:
                            Console.WriteLine("请输入你想取的金额:");
                            float a = float.Parse(Console.ReadLine());
                            if (a > sum)
                            {
                                throw new ArgumentOutOfRangeException("取款金额大于余额，请重新输入");
                            }
                            else
                            {
                                sum = sum - a;
                                Console.WriteLine("余额为{0}", sum);
                            }
                            break;
                        default:
                            Console.WriteLine("没有这个选项!");
                            break;
                    }
                }
               
            }
            catch (Exception)
            {

                Console.WriteLine("数据异常，已处理。");
            }
            finally 
            {
                Console.WriteLine("无异常！");
            }
        }
    }
}
